﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Xml;

namespace Fulcrum.ControlGenerator
{
    /// <summary>
    /// Configuration data about a given RoutedEvent
    /// </summary>
    class RoutedEventXmlConfiguration : Fulcrum.ControlGenerator.IRoutedEventConfiguration
    {
        public RoutedEventXmlConfiguration(XmlReader xmlReader)
        {
            const string DefaultEventArgsType = "RoutedEventArgs";
            const string DefaultHandlerType = "RoutedEventHandler";

            // TODO Name should never be null or empty
            // TODO EventArgsType should never be null or empty
            // TODO RoutingStrategy should never be null or empty
            // TODO HandlerType should never be null or empty
            // TODO Summary could be empty or null, but standardize
            // TODO Remarks could be empty or null, but standardize

            this.Name = xmlReader.GetAttribute("name");
            this.EventArgsType = XmlReaderHelp.GetOptionalAttributeValue(xmlReader, "eventArgsType", DefaultEventArgsType);
            this.RoutingStrategy = XmlReaderHelp.GetOptionalAttributeValue(xmlReader, "strategy", "Bubble");
            this.HandlerType = XmlReaderHelp.GetOptionalAttributeValue(xmlReader, "handlerType", DefaultHandlerType);
            this.Summary = xmlReader.GetAttribute("summary");
            this.Remarks = xmlReader.GetAttribute("remarks");

            if (false == String.Equals(this.EventArgsType, DefaultEventArgsType, StringComparison.InvariantCulture) &&
                String.Equals(this.HandlerType, DefaultHandlerType, StringComparison.InvariantCulture))
            {
                this.HandlerType = String.Format("EventHandler<{0}>", this.EventArgsType);
            }

            xmlReader.Read();
        }

        public string Name
        {
            get;
            private set;
        }

        public string Summary
        {
            get;
            private set;
        }

        public string Remarks
        {
            get;
            private set;
        }

        public string EventArgsType
        {
            get;
            private set;
        }

        public string RoutingStrategy
        {
            get;
            private set;
        }

        public string HandlerType
        {
            get;
            private set;
        }
    }
}
